<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  data() {
    return {
      form: {
        data: "",
        message: "", //描述
      },
      dialogVisible: false,
      dialogTitle: "", // 弹窗标题

      isloading: true,
      showDialog: false,
    };
  },
  methods: {
    // 关闭
    handleClose(done) {
      this.showDialog = false;
    },

    // 点击取消
    cancelDialog() {
      this.showDialog = false;
    },

    // 点击确定 发送请求
    async submit() {
      if (!(await this.validate())) {
        return;
      }

      let dataObj = {
        memberIdLst: this.userArr,
      };

      // 根据不同请求类型提交不同参数
      if (this.updateType == "Integral") {
        dataObj.changeIntegral = this.form.data;
        dataObj.tradeDesc = this.form.message;
        dataObj.typeId = this.integralId; //传过来的资产类型id
      } else if (this.updateType == "Amount") {
        dataObj.changeAmount = this.form.data;
        dataObj.tradeDesc = this.form.message;
      }

      let res = await this.$vFN.Http.post(
        {
          url: this.requestApi, //传过来的请求接口
          data: dataObj,
        },
        window
      );

      if (res._ok) {
        this.$vFN.Tools.messageSuccess(res.message);
        this.onSuccess();
        this.showDialog = false;
      }
    },

    init() {
      this.dialogTitle = `修改${this.titleText}`; // 传过来的 this.titleText
      this.isloading = false;
      this.showDialog = true;
    },

    // 回调
    onSuccess() {},

    // 校验
    validate() {
      let that = this;
      return new Promise((resolve, reject) => {
        that.$refs["editForm"].validate((valid) => {
          if (valid) {
            resolve(true);
          } else {
            resolve(false);
          }
        });
      });
    },

    // 验证数字
    validatorNumber(rule, value, callback) {
      // value = +value;
      // console.error(value);
      if (value == "") {
        callback(new Error("不能为空"));
      } else if (value == 0) {
        callback(new Error("不能为0"));
      } else {
        // 如果是资产类型，只能填正整数
        if (this.updateType == "Integral") {
          this.$vFN.Tools.validateStock(rule, value, callback);
        } else {
          this.$vFN.Tools.validateMoney(rule, value, callback);
        }
      }
    },
  },
  mounted() {
    this.init();
  },
};
</script>
